package com.examplemartin.jpademo.util;

import com.examplemartin.jpademo.constant.Session_Constant;
import com.examplemartin.jpademo.pojo.po.UserPO;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

public class SessionUtil {

  public static HttpSession getsession(){
    HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
    HttpSession session = request.getSession();
    if(ValidateMember.isEmpty(session)){
      return null;
    }
    return session;
  }

  public static UserPO getLoninUser(){
    HttpSession session = getsession();
    if(ValidateMember.isEmpty(session)){
      return null;
    }
    UserPO loginuser = (UserPO) session.getAttribute(Session_Constant.SESSION_LOING_USER_KEY);
    return  loginuser;
  }

}
